home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / rjs.lha / RJS / Transport / src / InetStream.C < prev    next >
C/C++ Source or Header  |  1991-06-14  |  1KB  |  57 lines

  1. #include <stdio.h>
  2. #include <osfcn.h>
  3. #include <libc.h>
  4. #include <errno.h>
  5. #include <string.h>
  6. #include <netdb.h>
  7. #include <iostream.h>
  8.  
  9. #include "Transport.h"
  10.  
  11. #include <RJS/Util.h>
  12.  
  13. extern "C" int rresvport(int *aport);
  14.  
  15. int RJS_InetStream::reserved_socket(int starting_port)
  16. {
  17.     td = ::rresvport(&starting_port);
  18.     return RJS_Socket::check_syscall(td,"rresvport");
  19. }
  20.  
  21. int RJS_InetStream::active(const RJS_InetAddress &ia)
  22. {
  23.     if (!ia.ss_ok()) {
  24.         ss_set(RJS_Status(errno));
  25.         if (return_on_error) return 0;
  26.         RJS_Util::crash_and_burn("RJS_InetStream","open",ss_message());
  27.     }
  28.     if (inuse()) close();
  29.     if (socket() && connect(ia)) {
  30.         ss_set(SS_success);
  31.         sex=Active;
  32.         return 1;
  33.     } 
  34.  
  35.     if (!return_on_error) 
  36.      RJS_Util::crash_and_burn("RJS_InetStream","socket_client",ss_message());
  37.        return 0;
  38. }
  39.  
  40. int RJS_InetStream::passive(const RJS_InetAddress &is)
  41. {
  42.     if (inuse()) close();
  43.     if (socket() && bind(is) && listen(SOMAXCONN)) {
  44.         ss_set(SS_success);
  45.         sex=Passive;
  46.         return 1;
  47.     }
  48.  
  49.     if (!return_on_error) 
  50.         RJS_Util::crash_and_burn("RJS_InetStream","socket_server",ss_message());
  51.     return 0;
  52.  
  53. }
  54.  
  55.  
  56.  
  57.